package com.sany.activity.service;

import com.sany.activity.domain.LeaveBillRepository;
import com.sany.activity.pojo.LeaveBill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class LeaveBillService {
    @Autowired
    private LeaveBillRepository leaveBillRepository;

    public List<LeaveBill> getAll(Long id){
        return leaveBillRepository.findByEmployeeId(id);
    }


    public boolean addLeaveBill(LeaveBill leaveBill){
        LeaveBill leaveBill1=leaveBillRepository.save(leaveBill);
        if(leaveBill1==null){
            return  false;
        }
        return true;
    }

    public boolean deleteLeaveBill(Long id){
        try {
            leaveBillRepository.deleteById(id);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    public LeaveBill findById(Long id){
        Optional<LeaveBill> leaveBillOptional=leaveBillRepository.findById(id);
        if(leaveBillOptional.isPresent()){
            return leaveBillOptional.get();
        }
        return null;
    }

    public boolean updateLeaveBill(LeaveBill leaveBill){
        LeaveBill leaveBill1=leaveBillRepository.save(leaveBill);
        if(leaveBill1==null){
            return  false;
        }
        return true;
    }
}
